package ir.values.users.instructions.alu;

import ir.types.datatypes.DataType;
import ir.types.datatypes.IntegerType;
import ir.values.Value;
import ir.values.users.instructions.Instruction;

public abstract class AluInst extends Instruction {
    protected Value operand1;
    protected Value operand2;
    public AluInst(DataType type, Value operand1, Value operand2) {
        super(null, type);
        this.operand1 = operand1;
        this.operand2 = operand2;
        operands.add(operand1);
        operands.add(operand2);
    }

    public AluInst(Value operand1, Value operand2) {
        this(IntegerType.I32, operand1, operand2);
    }

    public DataType getDataType() {
        return (DataType) type;
    }

    @Override
    public String parseLLVM() {
        StringBuilder sb = new StringBuilder();
        sb
                .append(parseUsingName())
                .append(" = ")
                .append(getInstOperator())
                .append(" ")
                .append(type.toString())
                .append(" ")
                .append(operand1.parseUsingName())
                .append(", ")
                .append(operand2.parseUsingName());
        return sb.toString();
    }
}
